package morseme;
/*
 * AddNumberForm.java
 *
 * Created on May 15, 2008, 2:04 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author tt
 */
import javax.microedition.lcdui.*;

public class AddNumberForm extends Form implements CommandListener{

private TextField nameTF = new TextField("Name ", "", 25, TextField.ANY);
private TextField numTF = new TextField("Number ", "", 15, TextField.PHONENUMBER);

private static Command addCmd = new Command("Add", Command.OK, 1);
private static Command cancelCmd = new Command("Cancel", Command.CANCEL, 1);
private PhoneBook pBook;

public AddNumberForm(PhoneBook pBook) {

super("Add Contact");
this.pBook = pBook;

this.append(nameTF);
this.append(numTF);

this.addCommand(addCmd);
this.addCommand(cancelCmd);
this.setCommandListener(this);
}

public void commandAction(Command c, Displayable d) {

if(c == addCmd){

if(nameTF.getString().length() == 0 || numTF.getString().length() == 0){
return;
}
this.pBook.saveNumber(nameTF.getString(), numTF.getString());
this.pBook.updatePhoneBook();
Display.getDisplay(MorseME.getMIDlet()).setCurrent(this.pBook);

}else if(c == cancelCmd){

Display.getDisplay(MorseME.getMIDlet()).setCurrent(this.pBook);
}
}
}

